Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper support for gitignore in AppWatcher #4917

Merged

Conversation

isaacroldan
Copy link
Contributor

@isaacroldan isaacroldan commented Nov 25, 2024

WHY are these changes introduced?

Fixes issues with file watching and extension creation detection during app dev.

WHAT is this pull request doing?

  • Improves file watching by using the ignore package to properly handle .gitignore files in extensions. If an extension defines it, anything in it will be ignored by the app watcher.
  • Fixes extension creation mid-dev by updating the file watcher when the app is reloaded.

How to test your changes?

  1. Create a new app with some extensions
  2. Add a .gitignore file to an extension directory
  3. Start dev and verify:
    • File changes matching .gitignore patterns are properly ignored
    • New extensions are properly detected mid-dev

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor Author

isaacroldan commented Nov 25, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from d975467 to 77a4f78 Compare November 25, 2024 15:27
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from 68457a7 to 1aa04a1 Compare November 25, 2024 15:27
@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 77a4f78 to 1b4002b Compare November 25, 2024 16:10
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from 1aa04a1 to f675d44 Compare November 25, 2024 16:10
@isaacroldan isaacroldan marked this pull request as ready for review November 25, 2024 16:27
@isaacroldan isaacroldan requested a review from a team as a code owner November 25, 2024 16:27
Copy link
Contributor

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

Copy link
Contributor

github-actions bot commented Nov 25, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.44% (+0.09% 🔼)
8740/11586
🟡 Branches
70.77% (+0.11% 🔼)
4266/6028
🟡 Functions
75.1% (+0.07% 🔼)
2289/3048
🟡 Lines
75.99% (+0.09% 🔼)
8264/10875
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app-event-watcher.ts
93.83% (-1.11% 🔻)
86.49% (-2.08% 🔻)
90.48%
98.61% (+0.02% 🔼)

Test suite run success

1968 tests passing in 892 suites.

Report generated by 🧪jest coverage report action from 0442d42

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 1b4002b to 0899271 Compare November 26, 2024 09:53
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from a045e02 to 9e17f4f Compare November 26, 2024 09:53
@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 0899271 to 4536258 Compare November 27, 2024 12:18
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from 9e17f4f to 6f07989 Compare November 27, 2024 12:18
@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from 4536258 to ff1bc64 Compare November 27, 2024 14:36
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from 6f07989 to b78e49c Compare November 27, 2024 14:36
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @isaacroldan! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/[email protected]

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@@ -150,6 +151,7 @@ export class AppEventWatcher extends EventEmitter {
if (!appEvent || appEvent.extensionEvents.length === 0) return

this.app = appEvent.app
if (appEvent.appWasReloaded) this.fileWatcher?.updateApp(this.app)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, how come we don't have to await for the fileWatcher to update the app here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateApp is not an async method, so we don't need to await :)

@isaacroldan isaacroldan force-pushed the 11-25-refactor_filewatcher_into_a_class branch from ff1bc64 to 599e99b Compare November 28, 2024 10:02
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch 3 times, most recently from e12fef5 to da90c96 Compare November 28, 2024 10:41
@isaacroldan isaacroldan changed the base branch from 11-25-refactor_filewatcher_into_a_class to graphite-base/4917 November 28, 2024 12:13
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from da90c96 to d6f0844 Compare November 28, 2024 12:13
@isaacroldan isaacroldan changed the base branch from graphite-base/4917 to main November 28, 2024 12:13
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch 2 times, most recently from d72edd6 to b2a69e8 Compare November 28, 2024 12:14
@isaacroldan isaacroldan force-pushed the 11-25-add_proper_support_for_gitignore_in_appwatcher branch from b2a69e8 to 0442d42 Compare November 29, 2024 09:29
Copy link
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't test it, but LGTM. Have you tested it in Windows? It's the typical thing that can be problematic there.

@@ -93,15 +81,20 @@ export class FileWatcher {
async start(): Promise<void> {
const {default: chokidar} = await import('chokidar')

this.watcher = chokidar.watch(this.watchPaths, {
const extensionDirectories = [...(this.app.configuration.extension_directories ?? ['extensions'])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about including extension_directories in the app model and adding the default value there?

Also, I see we are not using the value from the configuration in some places, like here. That approach would simplify the correct usage everywhere.

Comment on lines 91 to +97
'**/node_modules/**',
'**/.git/**',
'**/*.test.*',
'**/dist/**',
'**/*.swp',
'**/generated/**',
...this.customGitIgnoredPatterns,
'**/.gitignore',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd extract this list to a constant

Copy link
Contributor Author

I did not, will do it before merging 🙏

@isaacroldan isaacroldan merged commit 55da34b into main Nov 29, 2024
28 checks passed
@isaacroldan isaacroldan deleted the 11-25-add_proper_support_for_gitignore_in_appwatcher branch November 29, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants